package com.zw.yzk.kabu.adapter.flowtag;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hhl.library.OnInitSelectedPosition;
import com.zw.yzk.kabu.R;
import com.zw.yzk.kabu.model.GoodsDetailsModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by HanHailong on 15/10/19.
 */
public class GoodsTagAdapter extends BaseAdapter implements OnInitSelectedPosition {

    private Context mContext;
    private List<GoodsDetailsModel.Model> mDataList;

    public GoodsTagAdapter(List<GoodsDetailsModel.Model> list) {
        mDataList = new ArrayList<>();
        if (list != null) {
            mDataList.addAll(list);
        }
        notifyDataSetChanged();
    }

    public void refresh(List<GoodsDetailsModel.Model> list) {
        mDataList.clear();
        if (list != null) {
            mDataList.addAll(list);
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_goods_tag, parent, false);
        }

        TextView checkBox = (TextView) convertView.findViewById(R.id.property);
        GoodsDetailsModel.Model model = mDataList.get(position);
        checkBox.setText(model.getContent());

        return convertView;
    }

    @Override
    public boolean isSelectedPosition(int position) {
        //默认选中第一个
        return position == 0;
    }
}
